<?php
require_once ('../lib/config.php');
require_once ('../lib/facebook.php');
require_once ('../lib/friends.php');
require_once ('../lib/activity.php');
require_once ('../lib/test.php');
require_once ('f:\wamp\www\simpletest\autorun.php');
require_once ('../lib/init.php');

class TestTemplate extends UnitTestCase {
    
    function setUp(){
        global $login_button;
        try{
        $me = getOneself();
        }catch(Exception $e){
            print($login_button);
            exit();
        }
    }
    
    //refer to http://www.simpletest.org/en/unit_test_documentation.html
    function testGetOutMessageActivities(){ 

        
        $data = array(
            'name' => 'outMessageQuery',
            'fql_result_set' => Array(
                    '0' => Array(
                            'author_id' => '1246727707',
                            'body' => 'Hi, facebook friends.',
                            'created_time' => '1288750560',
                            'thread_id' => '1569070278129'
                        ),

                    '1' => Array(
                            'author_id' => '1246727707',
                            'body' => "There are public domain icons with good quality! (sounds like ads lol)",
                            'created_time' => '1287694540',
                            'thread_id' => '1356257881067'
                        )
                )
        );
        
        $data2 = array(
            'name' => 'outThreadQuery',
            'fql_result_set' => array(
                '0' => array(
                    'thread_id' => '1356257881067',
                    'subject' => 'This is probably useful',
                    'recipients' => Array(
                            '0' => '612139051',
                            '1' => '509836156',
                            '2' => '1246727707'
                        )
                ),
                '1' => array(
                    'thread_id' => '1569070278129',
                    'subject' => 'Please help my dissertation.',
                    'recipients' => Array(
                                   '0' => 732486215,
                                    '1' => 100000568852321,
                                    '2' => 534124579,
                                    '3' => 100000036440363,
                                    '4' => 100001753717079,
                                    '5' => 1382591304,
                                    '6' => 720480184,
                                    '7' => 100001442696712,
                                    '8' => 1676325929,
                                    '9' => 100000293254433,
                                    '10' => 15720738,
                                    '11' => 1468604886,
                                    '12' => 765455726,
                                    '13' => 1637340897,
                                    '14' => 612484233,
                                    '15' => 100000550522019,
                                    '16' => 1847145997,
                                    '17' => 639171815,
                                    '18' => 100000585892525,
                                    '19' => 645061280,
                                    '20' => 1246727707
                        )
                )
            )
        );
        $id = 612139051;
        $activities = array();
        $activities = getOutMessageActivities($id, $data, $data2, $activities);
        
        $this->assertTrue(is_array($activities));
        $this->assertTrue(count($activities) == 1);
        
        $id = 100001442696712;
        $activities = array();
        $activities = getOutMessageActivities($id, $data, $data2, $activities);
        
        $this->assertTrue(is_array($activities));
        $this->assertTrue(count($activities) == 1);
        
//        print_r($activities);
    }
    
    function testRealData(){
        $id = 612139051;
        $data = getActivities($id);
var_export($data);        
        $outMessageData = getResultSet('outMessageQuery', $data);
        $outThreadData = getResultSet('outThreadQuery', $data);
        $activities = array();
        $activities = getOutMessageActivities($id, $outMessageData, $outThreadData, $activities);
        $this->assertTrue(is_array($activities));

    }
}
?>